import { Directive } from 'vue'
import { message } from 'ant-design-vue'
import { store } from '@/store'
const handle: Directive = {
  mounted(el: Element, binding) {
    // 指令逻辑
    el.addEventListener('click', () => {
      const ActionKey = store.state.user?.actionKey
        ? store.state.user?.actionKey.split(',')
        : JSON.parse(
            localStorage.getItem('userInfo')!,
          )?.permissionActionKeyText?.split(',')
      if (!ActionKey.includes(binding.value.name)) {
        message.error('你没有该操作权限')
      } else {
        binding.value.val()
      }
    })
  },
}
export interface Directives {
  [name: string]: Directive
}
const directives: Directives = {
  handle,
}
export default directives
